package com.journaldev.spring.util;

import java.beans.PropertyEditorSupport;

import com.journaldev.spring.model.City;
import com.journaldev.spring.service.CityService;

public class SimpleCityEditor extends PropertyEditorSupport {
	
	private CityService cityDao;

    public SimpleCityEditor(CityService cityDao){
        this.cityDao = cityDao;
    }
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
    	City city = null;
        try {
            Integer id = Integer.parseInt(text);
            city = cityDao.getCityById(id);
            System.out.println("Department name:" + city.getCityName());
        } catch (NumberFormatException ex) {
            System.out.println("Department will be null");
        }
        setValue(city);
    }

}
